-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Resolve false negative for used-before-assignment with TYPE_CHECKING guard
#9990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve false negative for used-before-assignment with TYPE_CHECKING guard
#9990
Conversation
638a16a to
4c5272e
Compare
|
setting this to draft first, as i would like to check this more thoroughly. but feel free to discuss / give feedback! |
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #9990 +/- ##
=======================================
Coverage 95.80% 95.80%
=======================================
Files 174 174
Lines 18937 18939 +2
=======================================
+ Hits 18143 18145 +2
Misses 794 794
|
This comment has been minimized.
This comment has been minimized.
5bf0ee8 to
90983b4
Compare
This comment has been minimized.
This comment has been minimized.
aeb2789 to
6035068
Compare
This comment has been minimized.
This comment has been minimized.
6035068 to
b404520
Compare
This comment has been minimized.
This comment has been minimized.
b404520 to
95337f3
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
75f1fb4 to
4733d0f
Compare
This comment has been minimized.
This comment has been minimized.
4733d0f to
a3573a2
Compare
This comment has been minimized.
This comment has been minimized.
a3573a2 to
a27ad84
Compare
This comment has been minimized.
This comment has been minimized.
|
@jacobtylerwalls can i get a review for this PR? regarding the primer result, the sentry one seems legitimate. as an import is made under |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Just a small request to handle one more case.
This comment has been minimized.
This comment has been minimized.
|
Any idea about the new Django message for a nonlocal? |
|
seems that the message was raised due to a guarded function definition further down at line 1584. but from my understanding, this is a false positive? it should not flag as |
|
I wonder if we need to explicitly handle nonlocals somewhere. If you don't have bandwidth then I guess we can back out your last change and punt this to a new issue so that we don't cause more false positives. |
|
perhaps we should drop the latest commit and track this case with a separate issue? so that we can unblock #9964. you may assign the issue to me and i'll find time to work on it |
|
Very good--thank you! |
|
There is also the problem of from typing import TYPE_CHECKING
if TYPE_CHECKING:
from math import pi # unused-import false negativeIs it possible to fix that along the way? |
Again, thanks for this offer. I opened #10028 |
ad646cd to
16d14e8
Compare
hey no worries, i dropped the latest commit so this should be good to go.
sure thing, i added it to #10028 |
|
π€ Effect of this PR on checked open source code: π€ Effect on django:
Effect on sentry:
This comment was generated for commit 16d14e8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sentry primer looks legit.
Type of Changes
Description
In the function responsible for filtering nodes defined under a
TYPE_CHECKINGblock from consumption, usage scopes should only be updated whenused-before-assignmentis reported.However, there is currently a misalignment between the
_report_unfound_name_definition()and the filter function regarding when the error is raised. To resolve this,_report_unfound_name_definition()has been updated to return the check result, which is now passed to the filter function.Additionally, the check has been extended to handle cases where a class is defined within an
ifblock and used later.Closes #8893